<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="app">
    </div>
    <div id="height"></div>
    <div id="score"></div>
    <div id="hobby"></div>
</body>
<script>
    const app = document.getElementById('app')
    const height = document.getElementById('height')
    const score = document.getElementById('score')
    const hobby = document.getElementById('hobby')
    let vm
    function defineReactive(data, key, val) {
      vm = new Proxy(data, {
          get: function (target, key) {
              return target[key]
          },
          set:function (target,key, newVal) {
              if(val === newVal)return
              target[key] = newVal
              updated()
          }
      })
        console.log('proxy target:', vm)
    }

    function updated() {
        app.innerHTML = vm.name
        height.innerHTML = vm.height
        score.innerHTML = vm.score
        hobby.innerHTML = vm.hobby
    }

    const obj={
        name: '飒飒撒'
    }
    defineReactive(obj)

    setTimeout(()=>{
        vm.score = 60
        vm.name = 'Kate'
        vm.height = 120.333
        vm.hobby = '篮球'
    },2000)
</script>
</html>
